<?php

namespace App\Http\Controllers;

use App\Article;
use App\Category;
use App\Product;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class IndexController extends Controller
{
    public function index(Request $request)
    {
        $news = Category::where('sort', '1')->first();
        $documents = Category::where('sort', '2')->first();
        $notice = Category::where('sort', '3')->first();
        $lists1 = Article::where('category_id', $news->id)
            ->take(10)->get();
        $lists2 = Article::where('category_id', $documents->id)
            ->take(10)->get();
        $lists3 = Article::where('category_id', $notice->id)
            ->orderBy('updated_at', 'desc')
            ->take(10)->get();
        $products = Product::orderBy('updated_at', 'desc')->get();
        return view('index', [
            'id' => '0',
            'lists1' => $lists1,
            'lists2' => $lists2,
            'lists3' => $lists3,
            'products' => $products
        ]);
    }
}